function [uxt,uzt,vxt,vzt,sxxt,szzt,sxzt] = calc_uvs(A,f1,f2,f3,f4,f5,omega,t,x,vr,lambda,G)
%calc_uvs Calculation displacement(u), velocity(v) and stress(s) for a
%    given Rayleigh wave
%   
persistent uxmm uzmm vxmm vzmm exxmm ezzmm exzmm;
N = length(A);
if isempty(uxmm)
    uxmm = zeros(N,N);
    uzmm = zeros(N,N);
    vxmm = zeros(N,N);
    vzmm = zeros(N,N);
    exxmm = zeros(N,N);
    ezzmm = zeros(N,N);
    exzmm = zeros(N,N);
end
%
txv = t-x/vr;
txv_mask = (txv>0);
for i = 1:N
    swit = sin(omega(i)*txv).*txv_mask;
    cwit = cos(omega(i)*txv).*txv_mask;
    %
    uxmm(i,:)  =  A(i)*f1(i)*swit;
    uzmm(i,:)  =  A(i)*f2(i)*cwit;
    vxmm(i,:)  =  A(i)*f1(i)*omega(i)*cwit;
    vzmm(i,:)  = -A(i)*f2(i)*omega(i)*swit;
    exxmm(i,:) =  A(i)*f3(i)*cwit;
    ezzmm(i,:) =  A(i)*f4(i)*cwit;
    exzmm(i,:) =  A(i)*f5(i)*swit;
end
%
uxt = sum(uxmm);
uzt = sum(uzmm);
vxt = sum(vxmm);
vzt = sum(vzmm);
%
exx = sum(exxmm);
ezz = sum(ezzmm);
exz = sum(exzmm);
%
sxxt = (lambda+2*G)*exx+lambda*ezz;
szzt = lambda*exx+(lambda+2*G)*ezz;
sxzt = G*exz;
end

